package com.hbgjq.security.config;

import com.hbgjq.security.po.UserPo;
import org.springframework.security.access.PermissionEvaluator;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.util.List;

/**
 * @author :Gjq
 * @date :2021/1/6
 */
@Component
public class MyPermissionEvaluator implements PermissionEvaluator {
    /**
     *
     * @param authentication 权限信息包括用户信息等
     * @param o 注解中的参数1
     * @param o1 注解中的参数2
     * @return bool
     */
    @Override
    public boolean hasPermission(Authentication authentication, Object o, Object o1) {
        UserPo principal = (UserPo) authentication.getPrincipal();
        List<GrantedAuthority> myGrantedAuthorities = principal.getMyGrantedAuthorities();
        if (myGrantedAuthorities.contains(new MyGrantedAuthority(null,(String) o1))) return true;
        return false;
    }

    @Override
    public boolean hasPermission(Authentication authentication, Serializable serializable, String s, Object o) {
        System.out.println(2);
        return false;
    }
}
